The New York City Department of Health and Mental Hygiene (DOHMH) conducts unannounced restaurant inspections on an annual basis in order to check for compliance with policies on food handling, food temperature, personal hygiene of restaurant workers, and vermin control. Regulation violations are each worth a pre-specified number of points, which are totaled at the end of the inspection. Scores are converted into grades, where a lower score earns a higher grade. Each violation falls into one of three categories: A public health hazard, such as failing to store food at an appropriate temperature, results in a minimum score of 7 A critical violation, such as improperly washing raw vegetables prior to serving, results in a minimum score of 5 A general violation, such as improperly sanitizing cookware, results in a minimum score of 2 Additional points can then be assigned based on the severity of the violation, ranging from 1-5, at the discretion of the inspector. More details about the scoring and grading process can be found here. excluded pending grades and information where the borough is missing

0-13 points is an A B and those with 28 or more a C. I

Row

Chart A

Chart B

Row

Chart C

Chart D

Chart E

---
title: "NYC Restaurant Inspections"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    source: embed
    vertical_layout: scroll
---


```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(p8105.datasets)
library(plotly)

data("rest_inspec")
rest_insp = 
  rest_inspec %>% 
  filter(grade %in% c("A", "B", "C"), boro != "Missing") %>% 
  select(-camis, -phone, -record_date, -grade_date) 

nyc_rest = 
  rest_insp %>% 
  sample_frac(size = .1)
```

The New York City Department of Health and Mental Hygiene (DOHMH) conducts unannounced restaurant inspections on an annual basis in order to check for compliance with policies on food handling, food temperature, personal hygiene of restaurant workers, and vermin control. Regulation violations are each worth a pre-specified number of points, which are totaled at the end of the inspection. Scores are converted into grades, where a lower score earns a higher grade.
Each violation falls into one of three categories:
A public health hazard, such as failing to store food at an appropriate temperature, results in a minimum score of 7
A critical violation, such as improperly washing raw vegetables prior to serving, results in a minimum score of 5
A general violation, such as improperly sanitizing cookware, results in a minimum score of 2
Additional points can then be assigned based on the severity of the violation, ranging from 1-5, at the discretion of the inspector.
More details about the scoring and grading process can be found here.
 excluded pending grades and information where the borough is missing 
 
 0-13 points is an A
  B and those with 28 or more a C. I



Row 
-------------------------------------
### Chart A

```{r histogram}
nyc_rest %>%   
  separate(inspection_date, into = c("year", "month", "day")) %>% 
  plot_ly(x = ~year, type = "histogram", color = ~boro, colors = "viridis") 
```


### Chart B

```{r Box}
nyc_rest %>% 
  plot_ly(x = ~boro, y = ~score, type = "box", color = ~boro, colors = "viridis")
```

Row {.tabset .tabset-fade}
-------------------------------------
   
### Chart C

```{r Boxplot}


nyc_rest %>% 
  plot_ly(y = ~score, color = ~cuisine_description, type = "violin", colors = "viridis")
```


### Chart D

```{r}
nyc_rest %>% 
  plot_ly(x = ~violation_code , color = ~boro, type = "histogram", colors = "viridis", text = ~violation_description)



```


### Chart E

```{r}
nyc_rest %>% 
  filter(boro == "MANHATTAN") %>% 
  plot_ly(
     x = ~inspection_date, y = ~score, type = "scatter", mode = "markers", alpha = 0.5, color = ~grade, colors = "viridis")
```